package com.dlb.andorid.activity;

import android.graphics.Color;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import android.view.View;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.dlb.andorid.R;
import com.kwan.xframe.mvp.presenter.BasePresenter;
import com.kwan.xframe.mvp.view.activity.BaseCommonActivity;

import java.util.ArrayList;
import java.util.List;

public class FoodActivity extends BaseCommonActivity {

	@Override
	protected int getTopViewId() {
		return 0;
	}

	@Override
	protected int getMainViewId() {
		return R.layout.activity_food;
	}

	@Override
	protected int getBottomViewId() {
		return 0;
	}

	@Override
	protected BasePresenter getBasePresenter() {
		return null;
	}

	@Override
	protected void initData() {

	}

	@Override
	protected String getTitleTxt() {
		return "我晒美食";
	}

	@Override
	public String getPageName() {
		return null;
	}

	RecyclerView rv_1, rv_2, rv_3;

	BaseQuickAdapter<String, BaseViewHolder> mAdapter1, mAdapter2, mAdapter3;

	int mCurrentSelectTypePosition;

	@Override
	protected void initViews() {
		super.initViews();

		List<String> mTypes = new ArrayList<>();
		mTypes.add("全部");
		mTypes.add("向往的生活");
		mTypes.add("夏季");
		mTypes.add("凉拌");

		rv_1 = findViewById(R.id.rv_1);
		rv_1.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false));
		rv_1.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
		rv_1.setLayerType(View.LAYER_TYPE_HARDWARE, null);
		rv_1.setLayerType(View.LAYER_TYPE_NONE, null);
		rv_1.setHasFixedSize(true);
		rv_1.setItemAnimator(null);
		rv_1.setNestedScrollingEnabled(false);

		mAdapter1 = new BaseQuickAdapter<String, BaseViewHolder>(R.layout.list_item_food1,mTypes) {
			@Override
			protected void convert(BaseViewHolder helper, String item) {

			}
		};

		rv_1.setAdapter(mAdapter1);

		rv_2 = findViewById(R.id.rv_2);
		rv_2.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false));
		rv_2.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
		rv_2.setLayerType(View.LAYER_TYPE_HARDWARE, null);
		rv_2.setLayerType(View.LAYER_TYPE_NONE, null);
		rv_2.setHasFixedSize(true);
		rv_2.setItemAnimator(null);
		rv_2.setNestedScrollingEnabled(false);


		mAdapter2 = new BaseQuickAdapter<String, BaseViewHolder>(R.layout.list_item_home_type, mTypes) {
			@Override
			protected void convert(BaseViewHolder helper, String item) {

				if (mCurrentSelectTypePosition == helper.getLayoutPosition()) {
					helper.setBackgroundRes(R.id.tv_name, R.drawable.shape_home_type_selected);
					helper.setTextColor(R.id.tv_name, Color.WHITE);
				} else {
					helper.setBackgroundRes(R.id.tv_name, R.drawable.shape_home_type_normal);
					helper.setTextColor(R.id.tv_name, getResources().getColor(R.color.colorPrimary));
				}
				helper.setText(R.id.tv_name, item);
			}
		};

		mAdapter2.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {
			@Override
			public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
				mCurrentSelectTypePosition = position;
				//mPresenter.getProduct(mTypes.get(position).getId(), 1, 20);
				mAdapter2.notifyDataSetChanged();
			}
		});

		rv_2.setAdapter(mAdapter2);

		rv_3 = findViewById(R.id.rv_3);
		rv_3.setLayoutManager(new GridLayoutManager(this,2));
		rv_3.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
		rv_3.setLayerType(View.LAYER_TYPE_HARDWARE, null);
		rv_3.setLayerType(View.LAYER_TYPE_NONE, null);
		rv_3.setHasFixedSize(true);
		rv_3.setItemAnimator(null);
		rv_3.setNestedScrollingEnabled(false);


		mAdapter3 = new BaseQuickAdapter<String, BaseViewHolder>(R.layout.list_item_food3,mTypes) {
			@Override
			protected void convert(BaseViewHolder helper, String item) {

			}
		};

		rv_3.setAdapter(mAdapter3);

	}
}
